package com.xm.service.controller;

import com.xm.service.framework.feign.BookFeignClient;
import com.xm.service.framework.feign.UserFeignClient;
import com.xm.service.framework.utils.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;

@RestController
@RequiredArgsConstructor
@RequestMapping("/consumer/user")
public class ConsumerUserController {

//    private final RestTemplate restTemplate;

//    private static final String REST_URL_PREFIX = "http://service-book";
    private final UserFeignClient userFeignClient;


    @PostMapping("/login")
    public Result login(@RequestParam int uid, @RequestParam String pwd){

        return userFeignClient.login(uid,pwd);
    }

    @PostMapping("/register")
    public Result register(@RequestParam String uname,@RequestParam String password,
                               @RequestParam String email,@RequestParam int age,
                               @RequestParam String gender){
        return userFeignClient.register(uname,password,email,age,gender);
    }
    @RequestMapping("/verifyCode")//验证码
    public void generateImage(HttpServletResponse response) throws IOException {
        byte[] imageBytes = userFeignClient.generateImage();
        response.setContentType("image/jpeg");
        OutputStream out = response.getOutputStream();
        out.write(imageBytes);
        out.flush();
        out.close();
    }

    @RequestMapping("/checkCode")
    public int checkCode(@RequestParam String code){
        return userFeignClient.checkCode(code);
    }



}
